package LoadUnit
{
	import BasicEngine.Dispatcher;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.text.TextField;
	public class LoadLine extends Sprite
	{
		public var totalfileNum:TextField;
		public var  target:TextField;
		private var title:TextField;
		private var border:Shape;
		private var clrMask:Shape;
		private var timer:int = 0;
		
				
		public function LoadLine()
		{
			Init();
			this.x = 300;
			this.y = 250;
		}
		
		private function Init():void
		{
			var introduce:TextField = new TextField();
			introduce.text = "\t在LuaRobot 里面的机器人遵循动力学运动，机器人运动来源于\n\n发动机的动力，动力的作用下产生加速度。\na = F/m\nv = a * t\ns = v * t\n\n\t如你看到的，相同的发动机输出相同的动力，但如果质量不一\n\n样，产生不同的加速度。和现实一样，质量大的物体需要启动的\n\n时间需要更长，转弯的半径需要更多，这在LuaRobot中都会得到\n\n体现。你需要用自己的智慧编写出来符合这个世界的机器人。";
			addChild(introduce);
			introduce.y = -222;
			introduce.x = -100;
			introduce.width = 350;
			introduce.height = 400;
			introduce.wordWrap = true;
			title = new TextField();
			title.text = "Loading...";
			title.textColor = 0x666666;
			title.selectable = false;
			border = new Shape();
			border.graphics.beginFill(0x666666, 1);
			
			totalfileNum = new TextField();
			target = new TextField();

			for (var i:int = 0; i < 8; i++)
			{
				border.graphics.drawRoundRect(i * 14, 18, 12, 7, 2, 2);
			}
			
			clrMask = new Shape();
			clrMask.graphics.beginFill(0xff6600, 1);
			clrMask.graphics.drawRoundRect(1, 0, 10, 5, 2, 2);
			clrMask.y = 19;		
			addChild(title);
			addChild(border);
			addChild(clrMask);
			addChild(totalfileNum);
			addChild(target);
			totalfileNum.x = 50;
			var sp:TextField = new TextField();
			sp.text = "/";
			addChild(sp);
			sp.x = 110;
			target.x = 120
		}
		
		public function LoopAnimation(e:ProgressEvent):void
		{
			totalfileNum.text = e.bytesLoaded.toString()+"byte";
			target.text = e.bytesTotal.toString()+"byte";
			if (Dispatcher.Clock.SystemTime - timer > 100)
			{
			  clrMask.x += 14;
			  timer = Dispatcher.Clock.SystemTime;
			}
		    
			if (clrMask.x > 7 * 14)
			  clrMask.x = 0;
		}
	}
}